<?php
	namespace Home\Controller;

	class ArgumentsController extends CommonController{
		public function arguments(){
			$oid=$_GET['id'];
			if(!$oid){
				$this->redirect('Order/order_info');
				return false;
			}
			$_SESSION['arg']['oid']=$oid;
			$model=M('arguments');
			$li=$model->where("`status`=0 and `order_id`=".$oid." and `uid`=".$_SESSION['home']['id'])->select();
			$list=$model->field('ol.uid oluid,u.name,u.id uid,ol.ordernumber olo,ol.is_fu,ol.is_show,add.address,ol.add_id,ol.id,oi.goods_id,oi.num')->table('user u,order_list ol,`address` `add`,order_info oi')->where("u.id=ol.uid and oi.order_id= ol.id and ol.`add_id`=`add`.id and ol.id=".$oid)->find();
			$goodsmodel=M('Goods');
			$data=$goodsmodel->where("id=".$list['goods_id'])->find();
			$gimodel=M('Goods_img');
			$dat=$gimodel->where("goods_id=".$data['id'])->find();
			$dat['name']='/Public/Uploads/'.substr($dat['name'],0,4).'/'.substr($dat['name'],4,2).'/'.substr($dat['name'],6,2).'/80_'.$dat['name'];
			$this->assign('dat',$dat);
			$this->assign('login',$_SESSION['home']);
			$this->assign('data',$data);
			$this->assign('list',$list);
			$this->assign('li',$li);
			$this->display();
		}
		public function doarg(){
			$amodel=M('order_info');
			$olid=$amodel->where("id=".$_SESSION['arg']['oid'])->find()['order_id'];
			$bmodel=M('order_list');
			$show=$bmodel->where("id=".$olid)->find()['is_show'];
			if($show!=2){
				$this->error('订单未完成，不能评论');
				return false;
			}
			if(empty($_POST)){
				$this->error('请输入评论');
				return false;
			}
			$data['text']=$_POST['arg'];
			$data['order_id']=$_SESSION['arg']['oid'];
			$data['uid']=$_SESSION['home']['id'];
			unset($_SESSION['arg']);
			$model=M('Arguments');
			$res=$model->data($data)->add();
			if($res){
				$this->success('成功提交',U('Arguments/arguments'),2);
			}else{
				$this->error('请重新提交');
			}
		}
		
	}